﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using App.Utilities.Web.Handlers;
using System.Data;
using CRMBiz;
using Newtonsoft.Json;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for SMSTemplate
    /// </summary>
    public class SMSTemplate : BaseHandler
    {
        public override void OnMethodInvoke(OnMethodInvokeArgs e)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
            context.Response.Cache.SetExpires(DateTime.MinValue);
            context.Response.Cache.SetNoStore();

            //e.Cancel = true;

            SetResponseContentType(ResponseContentTypes.HTML);
        }

        public override void AfterMethodInvoke(object result)
        {
            base.AfterMethodInvoke(result);
        }
        public void SMSTemplateShowAll()
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(SMSTemplateHandler.BindSMSTemplate());
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public int SMSTemplateAdd(string SMSTemplate, string TemplateFormat, int CategoryID)
        {
            int intReturnValue = 0;
            try
            {
                intReturnValue = SMSTemplateHandler.AddSMSTemplate(SMSTemplate, TemplateFormat,CategoryID);
            }
            catch (Exception)
            {
                throw;
            }
            return intReturnValue;
        }
        public int SMSTemplateUpdate(int SMSTemplateID, string TemplateFormat, int CategoryID)
        {
            int intReturnValue = 0;
            try
            {
                intReturnValue = SMSTemplateHandler.UpdateSMSTemplate(SMSTemplateID, TemplateFormat,CategoryID);
            }
            catch (Exception)
            {
                throw;
            }
            return intReturnValue;
        }
       
        public bool SMSTemplateDelete(int SMSTemplateID)
        {
            bool flag = false;
            try
            {
                flag = SMSTemplateHandler.DeleteSMSTemplate(SMSTemplateID);
            }
            catch (Exception)
            {
                throw;
            }
            return flag;
        }

        public void getColumnName(string FilterCondition)
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(SMSTemplateHandler.getColumnName(FilterCondition));
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void getColumnName1()
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(SMSTemplateHandler.getColumnName1());
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void DisplayTemplateNode()
        {
            try
            {
                bool isSMS = true;
                string strJson = JsonConvert.SerializeObject(CategoryNodeHandler.GetCategoryNodesList(isSMS,false,false));
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void DisplayCategoryList()
        {
            try
            {
                bool isSMS = true;
                string strJson = JsonConvert.SerializeObject(CategoryNodeHandler.GetCategoryNodesList(isSMS,true,false));
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }
        

        public void GetSMSTemplateContentById(int smsTemplateId)
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(CategoryNodeHandler.GetSMSTemplateContent(smsTemplateId));
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}